#!/bin/bash

set -e

echo "checking go program..."

go version
if [ $? -eq 1 ]
then
  echo "go is not installed"
  exit
fi

echo "checking docker program..."

docker --version

if [ $? -eq 1 ]
then
  echo "docker is not installed"
  exit
fi


# apps=(aggregation auth manager shadow signal statistic)
apps=(aggregation auth manager shadow signal)

echo "checking app directory..."

# 检查app目录
for app in "${apps[@]}"
do
  if ! [ -e $app ]
  then
      echo "$app doesn't exist"
      exit
  elif ! [ -d $app ]
  then
    echo "$app isn't directory"
    exit
  elif ! [ -r $app ]
  then
    echo "$app isn't readable"
    exit
  fi
done

echo "building and pushing app images"

# 构建镜像并推送
for app in "${apps[@]}"
do
  echo "build $app image..."
  make buildimg app=$app

  echo  "push $app image..."
  make pushimg app=$app
done

echo "Done!"